package org.example.yuewen.solution16;

import java.math.BigInteger;

/**
 * @author: lynn
 * @Descript:
 * @date: 2021/5/13 21:21
 * @version: 1.0
 */
public class BigDataAdd {
    public static void main(String[] args) {
        String[] str={"20200201123456789123456789","20200201123456789"};
        String str0=str[0];
        String str1=str[1];
        BigInteger bigInteger1=new BigInteger("20200201123456789123456789");
        BigInteger bigInteger2=new BigInteger("20200201123456789");
        System.out.println(bigInteger1.add(bigInteger2));


        int length0=str0.length();
        int length1=str1.length();
        int length=length0>length1?length0:length1;
        if (length0<length){
            while (length0<length){
                str0="0"+str0;
                length0++;
            }
        }else {
            while (length1<length){
                str1="0"+str1;
                length1++;
            }
        }

        /*System.out.println(str0);
        System.out.println(str1);*/
        String res="";
        StringBuilder sb=new StringBuilder();
        String upper="0";
        for (int i = str0.length()-1; i >=0 ; i--) {
            int temp=Integer.valueOf(String.valueOf(str0.toCharArray()[i]))+Integer.valueOf(String.valueOf(str1.toCharArray()[i]))
                    +Integer.valueOf(upper);
            if (String.valueOf(temp).length()>1){
                upper=String.valueOf(String.valueOf(temp).toCharArray()[0]);
                sb.append(String.valueOf(String.valueOf(temp).toCharArray()[1]));
            }else {
                sb.append(temp);
            }
        }
        if (!upper.equals(0)){
            sb.append(upper);
        }
        System.out.println(sb.reverse());
    }
}
